package org.sample.service.impl;

import java.util.List;

import org.sample.commons.bean.BeanUtils;
import org.sample.dao.AdvertDao;
import org.sample.entity.Advert;
import org.sample.service.AdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdvertServiceImpl implements AdvertService {

    @Autowired
    private AdvertDao dao;

    @Override
    public List<Advert> getIdNameList() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void logicalDelete(Integer id) {
        Advert entity = dao.getOne(id);
        entity.setDeleted(true);
        dao.save(entity);
    }

    @Override
    public Advert saveNotNull(Advert entity) {
        if (entity.getId() == null) {
            return dao.save(entity);
        }
        Advert oldEntity = dao.getOne(entity.getId());
        BeanUtils.copyBeanNotNull(entity, oldEntity);
        return dao.save(oldEntity);
    }

}